package com.future.lock.home.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.future.baselib.activity.BaseActivity;
import com.future.lock.R;
import com.future.lock.common.RefreshDataUtils;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class AddMachineActivity extends BaseActivity {

    @Override
    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_add_machine);
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
        setTitle("添加设备");
    }

    @Override
    protected void initLogic() {

    }

    @Override
    protected void getBundleExtras(Bundle extras) {
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        boolean addLock = intent.getBooleanExtra("addLock", false);
        if (addLock){
            RefreshDataUtils.refreshGatewayList(this,refresh -> {
                if (refresh) {
                    Bundle bundle = new Bundle();
                    bundle.putString("gateway_id",intent.getStringExtra("gateway_id"));
                    startActivity(AddLockStep1Activity.class, bundle);
                }
            });
        }
    }

    @OnClick({R.id.iv_gateway, R.id.iv_lock})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_gateway:
                startActivity(AddGatewayStep1Activity.class);
                break;
            case R.id.iv_lock:
                RefreshDataUtils.refreshGatewayList(this,refresh -> {
                    if (refresh) {
                        startActivity(AddLockStep1Activity.class);
                    }
                });
                break;
        }
    }
}
